package cn.edu.sgu.www.mhxysy.controller.equipment;

import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.equipment.EquipmentViewAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.equipment.EquipmentViewAttribute;
import cn.edu.sgu.www.mhxysy.entity.except.Property;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.equipment.EquipmentViewAttributeService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "装备预览属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/equipment_view_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class EquipmentViewAttributeController {

    private final EquipmentViewAttributeService equipmentViewAttributeService;

    @Autowired
    public EquipmentViewAttributeController(EquipmentViewAttributeService equipmentViewAttributeService) {
        this.equipmentViewAttributeService = equipmentViewAttributeService;
    }

    @ApiOperation("添加装备预览属性")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated EquipmentViewAttributeDTO equipmentViewAttributeDTO) {
        equipmentViewAttributeService.insert(equipmentViewAttributeDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID修改装备预览属性")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated EquipmentViewAttributeDTO equipmentViewAttributeDTO) {
        equipmentViewAttributeService.updateById(equipmentViewAttributeDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询装备的可选属性")
    @RequestMapping(value = "/selectProperty", method = RequestMethod.GET)
    public JsonResult<List<Property>> selectProperty(
            @ApiParam(name = "type", value = "装备类型", required = false)
            @RequestParam(required = false) Integer type) {
        List<Property> list = equipmentViewAttributeService.selectProperty(type);

        return JsonResult.success(null, list);
    }

    @ApiOperation("查询装备预览属性")
    @RequestMapping(value = "/selectAttributes", method = RequestMethod.GET)
    public JsonResult<List<Map<String, Object>>> selectAttributes(
            @ApiParam(name = "equipmentId", value = "装备类型ID", required = false)
            @RequestParam(required = false) Integer equipmentId) {
        List<Map<String, Object>> list = equipmentViewAttributeService.selectAttributes(equipmentId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("分页查询装备预览属性列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<EquipmentViewAttribute>> selectByPage(Pager<EquipmentViewAttribute> pager) {
        Page<EquipmentViewAttribute> page = equipmentViewAttributeService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}